<%@page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<style type="text/css">
.li-1{
width: 100px;
}
.li-2{
width: 300px;
margin: 50px;
}
.li-3{
    width: 300px;
    margin: 50px;
}
.li-4{
    width: 300px;
}
li{
margin-top:10px;
margin-bottom:10px;
}
</style>
</head>
<body>
	<div class="linkbar"><a>运营管理</a>/<a>抽成管理</a></div>
	<div class="clear"></div>
	<form id="commission-fm" method="post">
	 <div>
	    <label for="name">请设置默认抽成（系统找不到对应区间会采取默认抽成）:</label>
		<input  name="extractDefault" class="easyui-textbox" style="width:80px;height:32px" value="${extractDefault }"/>元
	</div>
	<div>
	设置区间抽成：
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="">重新排序</a>
	</div> 
<%-- 	<div>
	   <ul>
	     <li><span class="li-1">序号</span><span class="li-2">大于：</span>~<span class="li-3">小于等于：</span><span class="li-4">抽成数：</span></li>
	     
	           
	           <c:if test="${not empty bfCommissions}">
	             <c:forEach items="${bfCommissions}" var="p" varStatus="i"> 
	               
	               
				    <li>
			            <span class="li-1">${i.index+1}</span>
			            <span class="li-2">
			                 <input  class="easyui-textbox" style="width:80px;height:32px" value="${p.sectionLeft}"/>元
			            </span>~
			            <span class="li-3">
			                  <input  class="easyui-textbox" style="width:80px;height:32px" value="${p.sectionRight}"/>元
			            </span>
			            <span class="li-4">
			                  <input  class="easyui-textbox" style="width:80px;height:32px" value="${p.extractMoney}"/>元
			           </span>
			           <c:if test="${!i.first}"> 
			                 <a href="javascript:void(0)" class="easyui-linkbutton" onclick="removeCommission(${p.orderNum})" style="width:100px;">删除区间</a>
			           </c:if>
		           </li>
		           </c:forEach>
			   </c:if>
	           <c:if test="${empty bfCommissions}">
	              <li><span class="li-1">1</span><span class="li-2"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span>~<span class="li-3"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span><span class="li-4"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span></li>
	              <li><span class="li-1">2</span><span class="li-2"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span>~<span class="li-3"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span><span class="li-4"><input  class="easyui-textbox" style="width:80px;height:32px" />元</span></li>
	           </c:if>
	     
	    
	  </ul>
	
	</div>
	
	<div style="margin-left:200px;margin-top:30px;">
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addCommission()" style="width:100px;">增加区间</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitCommission()" style="width:100px;">确定</a></div>
	 --%>
	
	
	
        <table id="addtest">
            <tr>
                <td>序号</td>
                <td>大于：</td>
                <td>~</td>
                <td>小于等于：</td>
                <td> 抽成数：</td>
                <td></td>
            </tr>
            <c:forEach items="${bfCommissions}" var="p" varStatus="ind">
            <tr>
                <td>${ind.index + 1}</td>
                <td>
                    <input type="text" name="contactList[${ind.index}].sectionLeft" value="${p.sectionLeft}">
                </td>
                <td></td>
                <td>
                    <input type="text" name="contactList[${ind.index}].sectionRight" value="${p.sectionRight}">
                </td>
                <td>
                    <input type="text" name="contactList[${ind.index}].extractMoney" value="${p.extractMoney}">
                </td>
                <td>
                   <c:if test="${!ind.first}"> 
			             <a href="javascript:void(0)"  onclick="removeCommission(${ind.index})" style="width:100px;">删除区间</a>
			       </c:if>
                </td>
            </tr>
            </c:forEach>
        </table>
            <div id="test">
               <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addCommission()" style="width:100px;">增加区间</a>
	           <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitCommission()" style="width:100px;">确定</a>
            </div>        
    </form>
	
	
	
	
	
	
	
	
	
	
	
	
	
	
<script type="text/javascript">
  var listUrl = "account/accountList.do";
  $(document).ready(function() {
  });
  function addCommission(){
    /* $("ul li:last").append('<li><span class="li-1">'+(parseInt($("ul li:last").children(".li-1").text())+1)+'</span><span class="li-2"><input name="" class="easyui-textbox" style="width:80px;height:32px"/>元 </span>~<span class="li-3"><input  class="easyui-textbox" style="width:80px;height:32px"/>元</span><span class="li-4"><input  class="easyui-textbox" style="width:80px;height:32px"/>元</span><a href="javascript:void(0)" class="easyui-linkbutton" onclick="removeCommission('+(parseInt($("ul li:last").children(".li-1").text())+1)+')" style="width:100px;">删除区间</a></li>');
 */  
        var addstep = parseInt($("#addtest tr:last").children("td:first").text())+ 1;
        $("#addtest tr:last").after("<tr>" + 
                "<td>"+ addstep +"</td>" + 
                "<td>" + 
                    "<input type='text' name='contactList[" + (parseInt(addstep)-1) + "].sectionLeft' >" +
                "</td>" + 
                "<td></td>" + 
                "<td>"+
                    "<input type='text' name='contactList[" + (parseInt(addstep)-1)  + "].sectionRight' >"+
                "</td>"+
                "<td>"+
                    "<input type='text' name='contactList[" + (parseInt(addstep)-1)  + "].extractMoney' >"+
                "</td>"+
                "<td>"+
                    "<a href='javascript:void(0)'  onclick='removeCommission(" + (parseInt(addstep)-1)  + ")' style='width:100px;'>删除区间</a>"+
                "</td>"+
            "</tr>");
   }

   
   function removeCommission(index){debugger;
      /* var silbings=$("#addtest tr:eq("+(parseInt(index)+1)+")").nextAll();
      for(var i = silbings.length - 1; i >= 0; i--){
         var cur = silbings[i];
         cur.firstChild.innerText=(parseInt(cur.firstChild.textContent)-1);
         cur.lastChild.children[0].setAttribute("onclick","removeCommission("+(parseInt(cur.firstChild.textContent)-1)+")");
      }
      $("#addtest tr:eq("+(parseInt(index)+1)+")").remove(); */
      var silbings = $("tr:eq("+parseInt(index+1)+")").nextAll();
      for(var i = silbings.length - 1; i >= 0; i--){
         var cur = silbings[i];
         cur.children[0].innerText=(parseInt(cur.children[0].innerText)-1);
         cur.lastElementChild.children[0].setAttribute("onclick","removeCommission("+(parseInt(cur.children[0].innerText)-1)+")");
      }
      $("tr:eq("+parseInt(index+1)+")").remove();
      
   }
   function submitCommission(){
	   $('#commission-fm').form('submit', {
	        url: 'rest/commissionAdd.do',        
	        onSubmit: function () {
	        	/* if(!$("input[name='type']").val()){
	        	  $.messager.alert('操作提示', "优惠券类型不能为空", 'error');	
	        	  return false; 
	        	}
	        	if(!$("#produceMoney").val() || isNaN($("#produceMoney").val())){
	        	  $.messager.alert('操作提示', "优惠券金额不能为空或者字符串，只能为数字", 'error');	
	        	  return false; 
	        	}
	        	if(!$("#produceAmount").val() || isNaN($("#produceAmount").val())){
	        	  $.messager.alert('操作提示', "优惠券数量不能为空或者字符串，只能为数字", 'error');	
	        	  return false; 
	        	}
	        	var couponType = $("#overdueTime").datebox("getValue");
	        	if(!couponType){
	        	  $.messager.alert('操作提示', "优惠券截至日期不能为空", 'error');	
	        	  return false; 
	        	} */
	        },
	        success: function (result) {   
	            var aas = jQuery.parseJSON(result);
	        	if (aas.retCode == "0000") {
					$.messager.alert('操作提示', "添加成功", 'info');							
				} else {
				   if(aas.retMsg){
				      $.messager.alert('操作提示', aas.retMsg, 'error');
				   }else{
				      $.messager.alert('操作提示', "添加失败", 'error');
				   }
				}
	        }
	    });
   
   }
</script>	
</body>
</html>